package guestbook;

import javax.jdo.PersistenceManager;
import java.util.List;

public class AddMsg {
	public void addmsg(Message msg){
        PersistenceManager pmInstance = PMF.get().getPersistenceManager();
        try{
            pmInstance.makePersistent(msg);
        }finally{
            pmInstance.close();
        }
    }
    public List<Message> list(){
        String queryStr = "select from " + Message.class.getName();
        List<Message> list = null;
        PersistenceManager pmInstance = PMF.get().getPersistenceManager();
        try{
            list = (List<Message>) pmInstance.newQuery(queryStr).execute();
            list = (List<Message>) pmInstance.detachCopyAll(list);
        }finally{
            pmInstance.close();
        }
        return list;
    }
     
    public void deleteAll(){
        String queryStr = "select from " + Message.class.getName();
        PersistenceManager pmInstance = PMF.get().getPersistenceManager();
        try{
            List<Message> list = (List<Message>) pmInstance.newQuery(queryStr).execute();
            pmInstance.deletePersistentAll(list);
        }finally{
            pmInstance.close();
        }
    }
}
